<template>
  <div class="panel-wrapper" :class="sceneStore.leftPanelVisible ? 'active' : ''">
    <div class="panel-inner">
      <div class="panel-handler" @click="toggleVisible">
        <SvgIcon icon-class="ic_close_gray" />
      </div>
      <div class="panel">
        <div v-if="showHeader" class="panel-header">{{ title }}</div>
        <slot></slot>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useSceneStore } from '@/store/scene';

interface IProps {
  title: string;
  showHeader: boolean;
}

defineOptions({
  name: 'LeftPanel',
});

const prop = withDefaults(defineProps<IProps>(), {
  title: '',
  showHeader: true,
});
const emit = defineEmits(['toggleVisible']);

const sceneStore = useSceneStore();

const toggleVisible = () => {
  emit('toggleVisible');
};
</script>

<style lang="less" scoped>
.panel-wrapper {
  position: absolute;
  top: 0;
  left: -296px;
  width: 356px;
  height: 100%;
  background: #0a0b0d;
  z-index: 1;
  transition: left 0.4s ease-out;
  .panel-inner {
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    .panel-handler {
      position: absolute;
      top: 0;
      right: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 28px;
      height: 28px;
      font-size: 18px;
      border-radius: 4px;
      cursor: pointer;
      .svg-icon {
        transition: transform 0.4s ease-out;
        transform: rotate(180deg);
      }
    }
    .panel {
      height: 100%;
      display: flex;
      flex-direction: column;

      .panel-header {
        height: 28px;
        font-size: 14px;
        color: #ffffff;
        background: #3d3d3d;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }
  }
  &.active {
    left: 100%;
    .panel-handler .svg-icon {
      transform: rotate(0deg);
    }
  }
}
</style>
